// pages/shopConcat/shopConcat.js
const common = require('../../utils/util.js')
const app = getApp()
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
var qqmapsdk;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        shopInfo: {},
        shopLocation: '',
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getShopInfo()
        qqmapsdk = new QQMapWX({
            key: 'CSSBZ-LXEWK-INHJO-AOC4H-FZ7OE-TJFRE'
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    getShopInfo: function() {
        wx.showLoading({
            title: '加载中'
        })
        const that = this
        let data = {
            activity: 785,
            store_id: wx.getStorageSync('storeId') ? wx.getStorageSync('storeId') : 1
        }
        common.post('Store/get_store_info', data).then(function(res) {
            wx.hideLoading()
            if (res.code == 204) {
                return
            }
            that.setData({
                shopInfo: res,
                shopLocation: res.address
            })
        }).catch(function(e) {})
    },

    goNavigation: function() {
        const that = this
        qqmapsdk.geocoder({
            //获取表单传入地址
            address: that.data.shopLocation, //地址参数，例：固定地址，address: '北京市海淀区彩和坊路海淀西大街74号'
            success: function(res) { //成功后的回调
                const latitude = res.result.location.lat
                const longitude = res.result.location.lng
                wx.openLocation({
                    latitude,
                    longitude,
                    name: that.data.shopLocation
                })
            }
        })
    },

    goPhoneCall: function(e) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone
        })
    }
})